#!/usr/bin/env bash


# ----------------------------------------------------------------------
# Filename	:  tmout
# Version	:  1.0
# Date		:  2022/02/21
# Author	:  Lz
# Email		:  liuzuo@kylinos.com.cn 
# History	:     
#            	   Version 1.0, 2022/02/21
# Function	:  会话登录超时限制
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------


# 测试主题
Title_Env_LTFLIB="安全加固(配置类) - 会话登录超时限制"


## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
	# 判断是否存在变量
	if [ "Z${Tmout_Access_SSRFlag}" == "Z" ];then
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "未定义变量 Tmout_Access_SSRFlag"
	fi

	# 判断变量是否为数字
	if [ "${Tmout_Access_SSRFlag}" -ge 0 ];then
		true
	else
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "Tmout_Access_SSRFlag 非法值: ${Tmout_Access_SSRFlag}"
	fi

        return $TPASS
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){

        return $TPASS
}


## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
        testcase_1

        return $TPASS
}


## TODO : 文件内容测试
#
testcase_1(){
	local flag_str="^ClientAliveInterval"

	# 错误选项
        local false_str="${flag_str}"
	# 正确选项
        local true_str="${flag_str} ${Tmout_Access_SSRFlag}"
	
	# 查看文件中配置
	local file_conf="/etc/ssh/sshd_config"
	local cmd="sudo cat ${file_conf}"
	eval ${cmd} | grep "$flag_str"
	eval ${cmd} | grep -q "${true_str}"
	CommRetParse_LTFLIB "${cmd}查询,要求${true_str}" "False"

	eval ${cmd} | grep -v "${true_str}" | grep "${false_str}"
	CommRetParse_LTFLIB "${cmd}查询,不存在'${true_str}'以外的值" "False" "yes"
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
